#!/bin/bash

#进入源码文件目录
PWD=`pwd`
echo $PWD
if [ $# != 2 ] || [ "$2" != 'online' -a "$2" != 'offline' ];
then
	echo "replace param error !!!"
	exit 1;
fi
ENV=$2
TYPE=$1
if [[ $2 == "online" ]];then
	echo "online env ,not need replace!"
	exit 0;
fi
cd $TYPE/src
#获取文件列表
filelist=`egrep -ir "(http|https):\/\/.+\.baidu\.com*+" * |grep -v svn | awk -F ":" '{print $1}' | uniq`
while read line
do
	#判断是否是注释的内容
	if [[ ${line:0:1} == "#" ]];then
		continue
	fi
	beforeTmp=`echo $line | awk -F ' ' '{print $1}'`
	afterTmp=`echo $line | awk -F ' ' '{print $2}'`
	before=`echo $beforeTmp | sed 's#\/#\\\/#g'`
	after=`echo $afterTmp | sed 's#\/#\\\/#g'`
	for file in $filelist
	do 
		`sed -i "s/$before/$after/g" $file`
	done
done  < $TYPE/qa_replace_url/replaceUrl.list
cd ../../
